<template>
	<view class="shenShop">
		<view class="shenShop_count">
			<view class="shenShop_two">
				<view class="shenShop_one_left">
					店铺头像
				</view>
				<view class="shenShop_one_right" @click="upImages">
					<image v-if="!params.avatar" src="../../../static/images/upImage.png" mode="aspectFill"></image>
					<image v-if="params.avatar" :src="params.avatar" mode="aspectFill"></image>
				</view>
			</view>
			<view class="shenShop_one">
				<view class="shenShop_one_left">
					店铺名称
				</view>
				<view class="shenShop_one_right">
					<input type="text" v-model="params.shopname" placeholder="请输入店铺名称">
					<text class="wlIcon-fanhui2 margin-left-xs"></text>
				</view>
			</view>
			<view class="shenShop_one">
				<view class="shenShop_one_left">
					店铺类型
				</view>
				<view class="shenShop_one_right">
					<radio shape="circle" :checked="params.shoptype==1"  style="transform:scale(0.7);" >码分商家</radio>
					<radio shape="circle" :checked="params.shoptype==0" style="transform:scale(0.7);" >易货商家</radio>
			
					<text class="wlIcon-fanhui2 margin-left-xs"></text>
				</view>
			</view>
			<view class="shenShop_one">
				<view class="shenShop_one_left">
					姓名
				</view>
				<view class="shenShop_one_right">
					<input type="text" v-model="params.name" placeholder="姓名">
					<text class="wlIcon-fanhui2 margin-left-xs"></text>
				</view>
			</view>
			<view class="shenShop_one">
				<view class="shenShop_one_left">
					身份证号
				</view>
				<view class="shenShop_one_right">
					<input type="text" v-model="params.number" placeholder="请输入身份证号">
					<text class="wlIcon-fanhui2 margin-left-xs"></text>
				</view>
			</view>
			<view class="shenShop_three">
				<view class="shenShop_one_left">
					证件图片
				</view>
				<view class="shenShop_three_image" @click="upzhengshu">
					<image v-if="!params.image" src="../../../static/images/upShenfen.png" mode="aspectFill"></image>
					<image v-if="params.image" :src="params.image" mode="aspectFill"></image>
				</view>
			</view>
			<view class="shenShop_one">
				<view class="shenShop_one_left">
					手机号
				</view>
				<view class="shenShop_one_right">
					<input type="text" v-model="params.mobile" placeholder="请输入手机号">
					<text class="wlIcon-fanhui2 margin-left-xs"></text>
				</view>
			</view>
			<view class="shenShop_one">
				<view class="shenShop_one_left">
					微信号
				</view>
				<view class="shenShop_one_right">
					<input type="text" v-model="params.wechat" placeholder="请输入微信号">
					<text class="wlIcon-fanhui2 margin-left-xs"></text>
				</view>
			</view>
			<view class="shenShop_three">
				<view class="shenShop_one_left">
					店铺简介
				</view>
				<view class="shenShop_three_image">
					<textarea v-model="params.bio" placeholder="请输入店铺简介"></textarea>
				</view>
			</view>
			<view class="shenShop_one">
				<view class="shenShop_one_left">
					地址
				</view>
				<view class="shenShop_one_right" @tap="btnClick">
					<input type="text" v-model="params.city" placeholder="请选择地址">
					<text class="wlIcon-fanhui2 margin-left-xs"></text>
				</view>
			</view>
		</view>
		<!-- 按钮 -->
		<view class="shenShop_button">
			<view class="shenShop_one" v-if="verify==2">
				审核中
			</view>
			<view class="shenShop_one" v-else-if="verify==3">
				审核通过
			</view>
			<view class="shenShop_one" v-else-if="verify==4" @click="confirmShop">
				审核失败，请重新提交
			</view>
			<view class="shenShop_one" v-else @click="confirmShop">
				提交
			</view>
		</view>
		<wanl-address ref='wanlAddress' @selectAddress="successSelectAddress"></wanl-address>
	</view>
</template>

<script>
	export default {
		data(){
			return {
				params:{
					shopname:"",
					name:"",
					number:"",
					mobile:"",
					image:"",
					wechat:"",
					avatar:"",
					bio:"",
					city:"",
					shoptype:0,
				},
				verify:"",
			}
		},
		onLoad() {
			this.getshopInfo()
		},
		methods:{
			btnClick() {
				this.$refs.wanlAddress.show()
			},
			successSelectAddress(address) {
				console.log(address)
				this.params.city=address.formatted_address
			},
			upImages(){
				uni.chooseImage({
					count:1,
					success: (res) => {
						console.log(res,'899999')
						this.uploadFile(res.tempFilePaths[0],'avatar')
					}
				})
			},
			upzhengshu(){
				uni.chooseImage({
					count:1,
					success: (res) => {
						console.log(res,'899999')
						this.uploadFile(res.tempFilePaths[0],'image')
					}
				})
			},
			uploadFile(file,type) {
				uni.request({
					url: '/wanlshop/common/uploadData',
					success: updata => {
						uni.uploadFile({
							url: updata.data.uploadurl,
							filePath: file,
							name: 'file',
							formData: updata.data.storage == 'local' ? null : updata.data.multipart,
							success: res => {
								// console.log('上传成功',res.data)
								var data =JSON.parse(res.data)
								if(type=='avatar'){
									this.params.avatar=data.data.fullurl
								}else{
									this.params.image=data.data.fullurl
								}
							},
							fail: error => {
								this.$wanlshop.msg(JSON.parse(error.data).msg);
							}
						});
					}
				});
			},
			async getshopInfo(){
				await uni.request({
					url:"/wanlshop/shop/shop_info",
					method:"POST",
					data:{},
					success: (res) => {
						if(res.data){
							this.params.shopname=res.data.shopname
							this.params.name=res.data.name
							this.params.number=res.data.number
							this.params.mobile=res.data.mobile
							this.params.image=res.data.image
							this.params.wechat=res.data.wechat
							this.params.avatar=res.data.avatar
							this.params.bio=res.data.bio
							this.params.city=res.data.city
							this.verify=res.data.verify
						}
						console.log(res.data,'店铺详情')
					}
				})
			},
			async confirmShop(){
				if(!this.params.avatar) return this.$wanlshop.msg('请选择店铺头像')
				if(!this.params.shopname) return this.$wanlshop.msg('请输入店铺名称')
				if(!this.params.name) return this.$wanlshop.msg('请输入姓名')
				if(!this.params.number) return this.$wanlshop.msg('请输入身份证号')
				if(!this.params.image) return this.$wanlshop.msg('请证件图片')
				if(!this.params.mobile) return this.$wanlshop.msg('请输入手机号')
				if(!this.params.wechat) return this.$wanlshop.msg('请输入微信号')
				if(!this.params.bio) return this.$wanlshop.msg('请输入店铺简介')
				if(!this.params.city) return this.$wanlshop.msg('请选择地址')
				await uni.request({
					url:"/wanlshop/shop/apply",
					method:"POST",
					data:this.params,
					success: (res) => {
						this.$wanlshop.msg('提交成功')
						this.getshopInfo()
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.shenShop{
		width: 100%;
		box-sizing: border-box;
		padding: 20rpx 24rpx 150rpx;
		.shenShop_count{
			width: 100%;
			background-color: #ffffff;
			box-sizing: border-box;
			padding: 0 20rpx;
			border-radius: 20rpx;
			.shenShop_one{
				width: 100%;
				height: 100rpx;
				display: flex;
				align-items: center;
				border-bottom: 1rpx solid #f7f7f7;
				.shenShop_one_left{
					width: 140rpx;
					font-size: 30rpx;
					color: #333333;
					font-weight: 800;
				}
				.shenShop_one_right{
					flex: 1;
					display: flex;
					align-items: center;
					input{
						flex: 1;
						height: 100rpx;
						font-size: 28rpx;
						text-align: right;
					}
				}
			}
			// 店铺头像
			.shenShop_two{
				height: 140rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				border-bottom: 1rpx solid #f7f7f7;
				.shenShop_one_left{
					width: 140rpx;
					font-size: 30rpx;
					color: #333333;
					font-weight: 800;
				}
				.shenShop_one_right{
					display: flex;
					align-items: center;
					image{
						width: 100rpx;
						height: 100rpx;
						border-radius: 10rpx;
					}
				}
			}
			// 身份正好
			.shenShop_three{
				width: 100%;
				box-sizing: border-box;
				padding: 30rpx 0;
				border-bottom: 1rpx solid #f7f7f7;
				.shenShop_one_left{
					width: 140rpx;
					font-size: 30rpx;
					color: #333333;
					font-weight: 800;
				}
				.shenShop_three_image{
					width: 100%;
					background-color: #f7f7f7;
					border-radius: 10rpx;
					box-sizing: border-box;
					padding:20rpx 10rpx 15rpx;
					margin-top: 20rpx;
					image{
						// width: 550rpx;
						width: 100%;
						height: 300rpx;
					}
					textarea{
						width: 100%;
						max-height: 200rpx;
						font-size: 28rpx;
					}
				}
			}
		}
		.shenShop_button{
			width: 100%;
			height: 140rpx;
			background-color: #ffffff;
			position: fixed;
			left: 0;
			bottom: 0;
			display: flex;
			align-items: center;
			justify-content: center;
			.shenShop_one{
				width: 80%;
				height: 90rpx;
				line-height: 90rpx;
				text-align: center;
				background-color: #fe6600;
				border-radius: 45rpx;
				font-size: 30rpx;
				color: #ffffff;
				
			}
		}
	}
</style>